<template>
  <div class="pagination-box">
    <el-pagination
      :current-page="currentPage"
      :page-size="pageSize"
      :page-sizes="pageSizes"
      :total="total"
      layout="total, sizes, prev, pager, next, jumper"
      @current-change="onCurrentChange"
      @size-change="onSizeChange"
    />
  </div>
</template>

<script setup lang="ts">
import { defineProps, defineEmits } from 'vue'

const props = defineProps({
  total: { type: Number, required: true },
  pageSize: { type: Number, default: 10 },
  currentPage: { type: Number, default: 1 },
  pageSizes: { type: Array<number>, default: () => [5, 10, 20, 50] },
})

const emits = defineEmits(['update:pageSize', 'update:currentPage', 'change'])

// 修改页码
const onCurrentChange = (page: number) => {
  emits('update:currentPage', page)
  emits('change', { page, pageSize: props.pageSize })
}

// 修改每页条数
const onSizeChange = (size: number) => {
  emits('update:pageSize', size)
  emits('change', { page: props.currentPage, pageSize: size })
}
</script>

<style scoped>
.pagination-box {
  display: flex;
  justify-content: center;
  margin-top: 20px;
}
</style>
